import { ListPage } from "custom/index";
import { getCustomerConsultationRecord, exportCustomerConsultationRecord } from '../api'
import { cooperationLevelOptions, statusOptions, starRatedOptions } from '../constant'
import RoomNameJsonColumn from './components/RoomNameJsonColumn.vue'
import RecordButton from './components/RecordButton.vue'
import StatusColumn from './components/StatusColumn.vue'
import RoomsNum from './components/RoomsNum.vue'
import { removeItem, addRecord, viewRecord, batchDeleteRows }  from './action'
import { addDialog, editDialog } from  './dialog'
import dayjs from 'dayjs'

const page = new ListPage('CustomerHotelManagement');

page
  .api(getCustomerConsultationRecord)
  .useSearch()
    .addInputItem('keyword', '酒店ID/酒店名称')
    .addItem({ prop: 'hotelsId', label: '酒店ID' })
    .addItem({ prop: 'title', label: '酒店名称' })
    .addItem({ prop: 'hotelsCityName', label: '城市' }) 
    .addDatePicker({ prop:'openingYear', label: '开业年份', type: 'year', format: 'YYYY', valueFormat: 'YYYY' })
    .addDatePicker({ prop: 'decorationYear', label: '装修年份', type: 'year', format: 'YYYY', valueFormat: 'YYYY' })
    .addNumberRangePicker(['scoreStart', 'scoreEnd'], { label: '评分' })
    .addSelect({ prop: 'cooperationLevel', label: '合作等级' }, cooperationLevelOptions)
    .addSelect({ prop: 'status', label: '营业状态' }, statusOptions)
    .addDateTimeRangePicker(['createtimeStart', 'createtimeEnd'], { label: '添加时间范围' })
    .addNumberRangePicker(['roomsNumStart', 'roomsNumEnd'], { label: '房间数量' })
    .addNumberRangePicker(['scoreNumStart', 'scoreNumEnd'], { label: '评价数量' })
    .addSelect({ prop: 'starRated', label: '酒店星级' }, starRatedOptions)
    .end()
  .useTable()
    .addSelectionColumn()
    // .useColumn('id').label('ID').end()
    // .addColumn({ prop: 'hotelsId', label: '酒店ID'})
    .addColumn({ prop: 'title', label: '酒店名称', minWidth: 230})
    .addColumn({ prop: 'hotelsCityName', label: '城市', minWidth: 60 })
    .addColumn({ prop: 'address', label: '地址', minWidth: 270})
    .addColumn({ prop: 'tel', label: '电话', minWidth: 180 })
    .useColumn('openingtime').label('开业时间').minWidth(106).formatter(row => row.openingtime ? dayjs(row.openingtime).format('YYYY') : '').sortable().end()
    .addColumn({ prop: 'decorationtime', label: '装修时间', minWidth: 90, formatter: (row) => row.decorationtime ? dayjs(row.decorationtime).format('YYYY') : ''})
    .useCustomColumn(RoomsNum, 'roomsNum').label('房间数量').minWidth(106).sortable().end()
    .useColumn('score').label('评分').minWidth(80).sortable().end()
    .addColumn({ prop: 'scoreNum', label: '评价数量', minWidth: 90})
    .addColumn({ prop: 'starRated', label: '酒店星级', minWidth: 90})
    // .addColumn({ prop: 'status', label: '营业状态', minWidth: 90, formatter: row => row.status === '无房型' ? '已关闭' : row.status})
    .useCustomColumn(StatusColumn, 'status').label('营业状态').minWidth(90).end()
    .addCustomColumn(RoomNameJsonColumn, { prop: 'roomNameJson', label: '房型', minWidth: 90})
    .addColumn({ prop: 'cooperationLevel', label: '合作等级'})
    .addColumn({ prop: 'createtime', label: '添加时间', minWidth: 170})
    .end()
  .addPagination()
  .useAuthButton()
    .useItem('add').content('新增').primary().addRow(addDialog).end()
    .useItem('delete').content('删除').danger().batchDeleteRows(batchDeleteRows).end()
    // .useItem('export').content('导出数据').exportData(exportCustomerConsultationRecord).end()
    .useItem('export').content('导出数据').exportExcel().end()
    .end()
  .useAuthColumn({ width: 260, className: 'overflow-visible' })
    .useItem('edit').content('编辑').editRow(editDialog).end()
    .useItem('record').setComponent(RecordButton).content('查看记录').action(viewRecord).end()
    .useItem('addrecord').content('添加记录').action(addRecord).end()
    .useItem('delete').content('删除').action(removeItem).end()

export default page
